<?php

/**
 * Created by PhpStorm.
 * User: wu
 * Date: 2017/4/20
 * Time: 18:16
 */
class C_home
{
    private $resource;

    private $call_items;

    private $back_items;

    private $resource_id;

    public function __construct()
    {
        $this->resource = 'C_Home';

        $this->call_items = array(
            "t" => time(),
            "k" => "",
            'uid' => '',
            'v' => API_VERSION,
            "enterpriseId" => "",
            "channelId" => "",
            "userType" => ""
        );

        $this->back_items = array(
            "news_product_list" => "",                 //新品上架,
            "market_product_list" => "",               //,
            "product_list" => "",                      //,
            "middle_function_area" => "",              //分类促销 和 企业信息,
            "advertise_list" => "",                    //广告促销,
            "promotion_list" => "",                    //促销首页,
        );
    }

    public function set_call_items($obj = array())
    {
        if (isset($obj['t'])) {
            $this->call_items['t'] = $obj['t'];
        }
        if (isset($obj['v'])) {
            $this->call_items['v'] = $obj['v'];
        }
        if (isset($obj['uid'])) {
            $this->call_items['uid'] = isset($obj['uid']) ? $obj['uid'] : '';
        }
        if (isset($obj['enterpriseId'])) {
            $this->call_items['enterpriseId'] = isset($obj['enterpriseId']) ? $obj['enterpriseId'] : '';
        }
        if (isset($obj['channelId'])) {
            $this->call_items['channelId'] = isset($obj['channelId']) ? $obj['channelId'] : '';
        }
        if (isset($obj['userType'])) {
            $this->call_items['userType'] = isset($obj['userType']) ? $obj['userType'] : '';
        }
        if (isset($obj['password']) && $obj['password']) {
            $this->call_items['k'] = md5($obj['password'] . $this->call_items['t']);
        }
        return $this->_get_url();
    }

    public function set_back_items($data = array())
    {
        if (isset($data['news_product_list'])) {
            $this->back_items['news_product_list'] = $data['news_product_list'];
        }
        if (isset($data['market_product_list'])) {
            $this->back_items['market_product_list'] = $data['market_product_list'];
        }
        if (isset($data['product_list'])) {
            $this->back_items['product_list'] = $data['product_list'];
        }
        if (isset($data['middle_function_area'])) {
            $this->back_items['middle_function_area'] = $data['middle_function_area'];
        }
        if (isset($data['advertise_list'])) {
            $this->back_items['advertise_list'] = $data['advertise_list'];
        }
        if (isset($data['promotion_list'])) {
            $this->back_items['promotion_list'] = $data['promotion_list'];
        }
    }

    public function set_resource_id($id)
    {
        $this->resource_id = $id;
        return $this->_get_url();
    }

    public function get_call_items()
    {
        return $this->call_items;
    }

    public function get_back_items()
    {
        return $this->back_items;
    }

    public function get_resource_id()
    {
        return $this->resource_id;
    }

    private function _get_url()
    {
        if ($this->resource_id) {
            return $this->resource . '/' . $this->resource_id . '/';
        } else {
            return $this->resource . '/';
        }
    }
}